// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Mapping;

public sealed partial class TextProperty : IProperty
{
	[JsonInclude, JsonPropertyName("analyzer")]
	public string? Analyzer { get; set; }
	[JsonInclude, JsonPropertyName("boost")]
	public double? Boost { get; set; }
	[JsonInclude, JsonPropertyName("copy_to")]
	[JsonConverter(typeof(SingleOrManyFieldsConverter))]
	public Elastic.Clients.Elasticsearch.Serverless.Fields? CopyTo { get; set; }
	[JsonInclude, JsonPropertyName("dynamic")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? Dynamic { get; set; }
	[JsonInclude, JsonPropertyName("eager_global_ordinals")]
	public bool? EagerGlobalOrdinals { get; set; }
	[JsonInclude, JsonPropertyName("fielddata")]
	public bool? Fielddata { get; set; }
	[JsonInclude, JsonPropertyName("fielddata_frequency_filter")]
	public Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter? FielddataFrequencyFilter { get; set; }
	[JsonInclude, JsonPropertyName("fields")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? Fields { get; set; }
	[JsonInclude, JsonPropertyName("ignore_above")]
	public int? IgnoreAbove { get; set; }
	[JsonInclude, JsonPropertyName("index")]
	public bool? Index { get; set; }
	[JsonInclude, JsonPropertyName("index_options")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.IndexOptions? IndexOptions { get; set; }
	[JsonInclude, JsonPropertyName("index_phrases")]
	public bool? IndexPhrases { get; set; }
	[JsonInclude, JsonPropertyName("index_prefixes")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes? IndexPrefixes { get; set; }

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("meta")]
	public IDictionary<string, string>? Meta { get; set; }
	[JsonInclude, JsonPropertyName("norms")]
	public bool? Norms { get; set; }
	[JsonInclude, JsonPropertyName("position_increment_gap")]
	public int? PositionIncrementGap { get; set; }
	[JsonInclude, JsonPropertyName("properties")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? Properties { get; set; }
	[JsonInclude, JsonPropertyName("search_analyzer")]
	public string? SearchAnalyzer { get; set; }
	[JsonInclude, JsonPropertyName("search_quote_analyzer")]
	public string? SearchQuoteAnalyzer { get; set; }
	[JsonInclude, JsonPropertyName("similarity")]
	public string? Similarity { get; set; }
	[JsonInclude, JsonPropertyName("store")]
	public bool? Store { get; set; }
	[JsonInclude, JsonPropertyName("term_vector")]
	public Elastic.Clients.Elasticsearch.Serverless.Mapping.TermVectorOption? TermVector { get; set; }

	[JsonInclude, JsonPropertyName("type")]
	public string Type => "text";
}

public sealed partial class TextPropertyDescriptor<TDocument> : SerializableDescriptor<TextPropertyDescriptor<TDocument>>, IBuildableDescriptor<TextProperty>
{
	internal TextPropertyDescriptor(Action<TextPropertyDescriptor<TDocument>> configure) => configure.Invoke(this);

	public TextPropertyDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private double? BoostValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Fields? CopyToValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? DynamicValue { get; set; }
	private bool? EagerGlobalOrdinalsValue { get; set; }
	private bool? FielddataValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter? FielddataFrequencyFilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor FielddataFrequencyFilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor> FielddataFrequencyFilterDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? FieldsValue { get; set; }
	private int? IgnoreAboveValue { get; set; }
	private bool? IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.IndexOptions? IndexOptionsValue { get; set; }
	private bool? IndexPhrasesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes? IndexPrefixesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor IndexPrefixesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor> IndexPrefixesDescriptorAction { get; set; }
	private IDictionary<string, string>? MetaValue { get; set; }
	private bool? NormsValue { get; set; }
	private int? PositionIncrementGapValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? PropertiesValue { get; set; }
	private string? SearchAnalyzerValue { get; set; }
	private string? SearchQuoteAnalyzerValue { get; set; }
	private string? SimilarityValue { get; set; }
	private bool? StoreValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TermVectorOption? TermVectorValue { get; set; }

	public TextPropertyDescriptor<TDocument> Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Boost(double? boost)
	{
		BoostValue = boost;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> CopyTo(Elastic.Clients.Elasticsearch.Serverless.Fields? copyTo)
	{
		CopyToValue = copyTo;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Dynamic(Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? dynamic)
	{
		DynamicValue = dynamic;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> EagerGlobalOrdinals(bool? eagerGlobalOrdinals = true)
	{
		EagerGlobalOrdinalsValue = eagerGlobalOrdinals;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Fielddata(bool? fielddata = true)
	{
		FielddataValue = fielddata;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> FielddataFrequencyFilter(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter? fielddataFrequencyFilter)
	{
		FielddataFrequencyFilterDescriptor = null;
		FielddataFrequencyFilterDescriptorAction = null;
		FielddataFrequencyFilterValue = fielddataFrequencyFilter;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> FielddataFrequencyFilter(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor descriptor)
	{
		FielddataFrequencyFilterValue = null;
		FielddataFrequencyFilterDescriptorAction = null;
		FielddataFrequencyFilterDescriptor = descriptor;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> FielddataFrequencyFilter(Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor> configure)
	{
		FielddataFrequencyFilterValue = null;
		FielddataFrequencyFilterDescriptor = null;
		FielddataFrequencyFilterDescriptorAction = configure;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? fields)
	{
		FieldsValue = fields;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Fields(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> IgnoreAbove(int? ignoreAbove)
	{
		IgnoreAboveValue = ignoreAbove;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Index(bool? index = true)
	{
		IndexValue = index;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> IndexOptions(Elastic.Clients.Elasticsearch.Serverless.Mapping.IndexOptions? indexOptions)
	{
		IndexOptionsValue = indexOptions;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> IndexPhrases(bool? indexPhrases = true)
	{
		IndexPhrasesValue = indexPhrases;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> IndexPrefixes(Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes? indexPrefixes)
	{
		IndexPrefixesDescriptor = null;
		IndexPrefixesDescriptorAction = null;
		IndexPrefixesValue = indexPrefixes;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> IndexPrefixes(Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor descriptor)
	{
		IndexPrefixesValue = null;
		IndexPrefixesDescriptorAction = null;
		IndexPrefixesDescriptor = descriptor;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> IndexPrefixes(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor> configure)
	{
		IndexPrefixesValue = null;
		IndexPrefixesDescriptor = null;
		IndexPrefixesDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	public TextPropertyDescriptor<TDocument> Meta(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		MetaValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Norms(bool? norms = true)
	{
		NormsValue = norms;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> PositionIncrementGap(int? positionIncrementGap)
	{
		PositionIncrementGapValue = positionIncrementGap;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Properties(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? properties)
	{
		PropertiesValue = properties;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Properties(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Properties(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> SearchAnalyzer(string? searchAnalyzer)
	{
		SearchAnalyzerValue = searchAnalyzer;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> SearchQuoteAnalyzer(string? searchQuoteAnalyzer)
	{
		SearchQuoteAnalyzerValue = searchQuoteAnalyzer;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Similarity(string? similarity)
	{
		SimilarityValue = similarity;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> Store(bool? store = true)
	{
		StoreValue = store;
		return Self;
	}

	public TextPropertyDescriptor<TDocument> TermVector(Elastic.Clients.Elasticsearch.Serverless.Mapping.TermVectorOption? termVector)
	{
		TermVectorValue = termVector;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (CopyToValue is not null)
		{
			writer.WritePropertyName("copy_to");
			JsonSerializer.Serialize(writer, CopyToValue, options);
		}

		if (DynamicValue is not null)
		{
			writer.WritePropertyName("dynamic");
			JsonSerializer.Serialize(writer, DynamicValue, options);
		}

		if (EagerGlobalOrdinalsValue.HasValue)
		{
			writer.WritePropertyName("eager_global_ordinals");
			writer.WriteBooleanValue(EagerGlobalOrdinalsValue.Value);
		}

		if (FielddataValue.HasValue)
		{
			writer.WritePropertyName("fielddata");
			writer.WriteBooleanValue(FielddataValue.Value);
		}

		if (FielddataFrequencyFilterDescriptor is not null)
		{
			writer.WritePropertyName("fielddata_frequency_filter");
			JsonSerializer.Serialize(writer, FielddataFrequencyFilterDescriptor, options);
		}
		else if (FielddataFrequencyFilterDescriptorAction is not null)
		{
			writer.WritePropertyName("fielddata_frequency_filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor(FielddataFrequencyFilterDescriptorAction), options);
		}
		else if (FielddataFrequencyFilterValue is not null)
		{
			writer.WritePropertyName("fielddata_frequency_filter");
			JsonSerializer.Serialize(writer, FielddataFrequencyFilterValue, options);
		}

		if (FieldsValue is not null)
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (IgnoreAboveValue.HasValue)
		{
			writer.WritePropertyName("ignore_above");
			writer.WriteNumberValue(IgnoreAboveValue.Value);
		}

		if (IndexValue.HasValue)
		{
			writer.WritePropertyName("index");
			writer.WriteBooleanValue(IndexValue.Value);
		}

		if (IndexOptionsValue is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, IndexOptionsValue, options);
		}

		if (IndexPhrasesValue.HasValue)
		{
			writer.WritePropertyName("index_phrases");
			writer.WriteBooleanValue(IndexPhrasesValue.Value);
		}

		if (IndexPrefixesDescriptor is not null)
		{
			writer.WritePropertyName("index_prefixes");
			JsonSerializer.Serialize(writer, IndexPrefixesDescriptor, options);
		}
		else if (IndexPrefixesDescriptorAction is not null)
		{
			writer.WritePropertyName("index_prefixes");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor(IndexPrefixesDescriptorAction), options);
		}
		else if (IndexPrefixesValue is not null)
		{
			writer.WritePropertyName("index_prefixes");
			JsonSerializer.Serialize(writer, IndexPrefixesValue, options);
		}

		if (MetaValue is not null)
		{
			writer.WritePropertyName("meta");
			JsonSerializer.Serialize(writer, MetaValue, options);
		}

		if (NormsValue.HasValue)
		{
			writer.WritePropertyName("norms");
			writer.WriteBooleanValue(NormsValue.Value);
		}

		if (PositionIncrementGapValue.HasValue)
		{
			writer.WritePropertyName("position_increment_gap");
			writer.WriteNumberValue(PositionIncrementGapValue.Value);
		}

		if (PropertiesValue is not null)
		{
			writer.WritePropertyName("properties");
			JsonSerializer.Serialize(writer, PropertiesValue, options);
		}

		if (!string.IsNullOrEmpty(SearchAnalyzerValue))
		{
			writer.WritePropertyName("search_analyzer");
			writer.WriteStringValue(SearchAnalyzerValue);
		}

		if (!string.IsNullOrEmpty(SearchQuoteAnalyzerValue))
		{
			writer.WritePropertyName("search_quote_analyzer");
			writer.WriteStringValue(SearchQuoteAnalyzerValue);
		}

		if (!string.IsNullOrEmpty(SimilarityValue))
		{
			writer.WritePropertyName("similarity");
			writer.WriteStringValue(SimilarityValue);
		}

		if (StoreValue.HasValue)
		{
			writer.WritePropertyName("store");
			writer.WriteBooleanValue(StoreValue.Value);
		}

		if (TermVectorValue is not null)
		{
			writer.WritePropertyName("term_vector");
			JsonSerializer.Serialize(writer, TermVectorValue, options);
		}

		writer.WritePropertyName("type");
		writer.WriteStringValue("text");
		writer.WriteEndObject();
	}

	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter? BuildFielddataFrequencyFilter()
	{
		if (FielddataFrequencyFilterValue is not null)
		{
			return FielddataFrequencyFilterValue;
		}

		if ((object)FielddataFrequencyFilterDescriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter?> buildable)
		{
			return buildable.Build();
		}

		if (FielddataFrequencyFilterDescriptorAction is not null)
		{
			var descriptor = new Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor(FielddataFrequencyFilterDescriptorAction);
			if ((object)descriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter?> buildableFromAction)
			{
				return buildableFromAction.Build();
			}
		}

		return null;
	}

	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes? BuildIndexPrefixes()
	{
		if (IndexPrefixesValue is not null)
		{
			return IndexPrefixesValue;
		}

		if ((object)IndexPrefixesDescriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes?> buildable)
		{
			return buildable.Build();
		}

		if (IndexPrefixesDescriptorAction is not null)
		{
			var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor(IndexPrefixesDescriptorAction);
			if ((object)descriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes?> buildableFromAction)
			{
				return buildableFromAction.Build();
			}
		}

		return null;
	}

	TextProperty IBuildableDescriptor<TextProperty>.Build() => new()
	{
		Analyzer = AnalyzerValue,
		Boost = BoostValue,
		CopyTo = CopyToValue,
		Dynamic = DynamicValue,
		EagerGlobalOrdinals = EagerGlobalOrdinalsValue,
		Fielddata = FielddataValue,
		FielddataFrequencyFilter = BuildFielddataFrequencyFilter(),
		Fields = FieldsValue,
		IgnoreAbove = IgnoreAboveValue,
		Index = IndexValue,
		IndexOptions = IndexOptionsValue,
		IndexPhrases = IndexPhrasesValue,
		IndexPrefixes = BuildIndexPrefixes(),
		Meta = MetaValue,
		Norms = NormsValue,
		PositionIncrementGap = PositionIncrementGapValue,
		Properties = PropertiesValue,
		SearchAnalyzer = SearchAnalyzerValue,
		SearchQuoteAnalyzer = SearchQuoteAnalyzerValue,
		Similarity = SimilarityValue,
		Store = StoreValue,
		TermVector = TermVectorValue
	};
}

public sealed partial class TextPropertyDescriptor : SerializableDescriptor<TextPropertyDescriptor>, IBuildableDescriptor<TextProperty>
{
	internal TextPropertyDescriptor(Action<TextPropertyDescriptor> configure) => configure.Invoke(this);

	public TextPropertyDescriptor() : base()
	{
	}

	private string? AnalyzerValue { get; set; }
	private double? BoostValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Fields? CopyToValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? DynamicValue { get; set; }
	private bool? EagerGlobalOrdinalsValue { get; set; }
	private bool? FielddataValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter? FielddataFrequencyFilterValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor FielddataFrequencyFilterDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor> FielddataFrequencyFilterDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? FieldsValue { get; set; }
	private int? IgnoreAboveValue { get; set; }
	private bool? IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.IndexOptions? IndexOptionsValue { get; set; }
	private bool? IndexPhrasesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes? IndexPrefixesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor IndexPrefixesDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor> IndexPrefixesDescriptorAction { get; set; }
	private IDictionary<string, string>? MetaValue { get; set; }
	private bool? NormsValue { get; set; }
	private int? PositionIncrementGapValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? PropertiesValue { get; set; }
	private string? SearchAnalyzerValue { get; set; }
	private string? SearchQuoteAnalyzerValue { get; set; }
	private string? SimilarityValue { get; set; }
	private bool? StoreValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TermVectorOption? TermVectorValue { get; set; }

	public TextPropertyDescriptor Analyzer(string? analyzer)
	{
		AnalyzerValue = analyzer;
		return Self;
	}

	public TextPropertyDescriptor Boost(double? boost)
	{
		BoostValue = boost;
		return Self;
	}

	public TextPropertyDescriptor CopyTo(Elastic.Clients.Elasticsearch.Serverless.Fields? copyTo)
	{
		CopyToValue = copyTo;
		return Self;
	}

	public TextPropertyDescriptor Dynamic(Elastic.Clients.Elasticsearch.Serverless.Mapping.DynamicMapping? dynamic)
	{
		DynamicValue = dynamic;
		return Self;
	}

	public TextPropertyDescriptor EagerGlobalOrdinals(bool? eagerGlobalOrdinals = true)
	{
		EagerGlobalOrdinalsValue = eagerGlobalOrdinals;
		return Self;
	}

	public TextPropertyDescriptor Fielddata(bool? fielddata = true)
	{
		FielddataValue = fielddata;
		return Self;
	}

	public TextPropertyDescriptor FielddataFrequencyFilter(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter? fielddataFrequencyFilter)
	{
		FielddataFrequencyFilterDescriptor = null;
		FielddataFrequencyFilterDescriptorAction = null;
		FielddataFrequencyFilterValue = fielddataFrequencyFilter;
		return Self;
	}

	public TextPropertyDescriptor FielddataFrequencyFilter(Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor descriptor)
	{
		FielddataFrequencyFilterValue = null;
		FielddataFrequencyFilterDescriptorAction = null;
		FielddataFrequencyFilterDescriptor = descriptor;
		return Self;
	}

	public TextPropertyDescriptor FielddataFrequencyFilter(Action<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor> configure)
	{
		FielddataFrequencyFilterValue = null;
		FielddataFrequencyFilterDescriptor = null;
		FielddataFrequencyFilterDescriptorAction = configure;
		return Self;
	}

	public TextPropertyDescriptor Fields(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? fields)
	{
		FieldsValue = fields;
		return Self;
	}

	public TextPropertyDescriptor Fields<TDocument>(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor Fields<TDocument>(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		FieldsValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor IgnoreAbove(int? ignoreAbove)
	{
		IgnoreAboveValue = ignoreAbove;
		return Self;
	}

	public TextPropertyDescriptor Index(bool? index = true)
	{
		IndexValue = index;
		return Self;
	}

	public TextPropertyDescriptor IndexOptions(Elastic.Clients.Elasticsearch.Serverless.Mapping.IndexOptions? indexOptions)
	{
		IndexOptionsValue = indexOptions;
		return Self;
	}

	public TextPropertyDescriptor IndexPhrases(bool? indexPhrases = true)
	{
		IndexPhrasesValue = indexPhrases;
		return Self;
	}

	public TextPropertyDescriptor IndexPrefixes(Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes? indexPrefixes)
	{
		IndexPrefixesDescriptor = null;
		IndexPrefixesDescriptorAction = null;
		IndexPrefixesValue = indexPrefixes;
		return Self;
	}

	public TextPropertyDescriptor IndexPrefixes(Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor descriptor)
	{
		IndexPrefixesValue = null;
		IndexPrefixesDescriptorAction = null;
		IndexPrefixesDescriptor = descriptor;
		return Self;
	}

	public TextPropertyDescriptor IndexPrefixes(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor> configure)
	{
		IndexPrefixesValue = null;
		IndexPrefixesDescriptor = null;
		IndexPrefixesDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Metadata about the field.</para>
	/// </summary>
	public TextPropertyDescriptor Meta(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		MetaValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	public TextPropertyDescriptor Norms(bool? norms = true)
	{
		NormsValue = norms;
		return Self;
	}

	public TextPropertyDescriptor PositionIncrementGap(int? positionIncrementGap)
	{
		PositionIncrementGapValue = positionIncrementGap;
		return Self;
	}

	public TextPropertyDescriptor Properties(Elastic.Clients.Elasticsearch.Serverless.Mapping.Properties? properties)
	{
		PropertiesValue = properties;
		return Self;
	}

	public TextPropertyDescriptor Properties<TDocument>(Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument> descriptor)
	{
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor Properties<TDocument>(Action<Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>> configure)
	{
		var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.PropertiesDescriptor<TDocument>();
		configure?.Invoke(descriptor);
		PropertiesValue = descriptor.PromisedValue;
		return Self;
	}

	public TextPropertyDescriptor SearchAnalyzer(string? searchAnalyzer)
	{
		SearchAnalyzerValue = searchAnalyzer;
		return Self;
	}

	public TextPropertyDescriptor SearchQuoteAnalyzer(string? searchQuoteAnalyzer)
	{
		SearchQuoteAnalyzerValue = searchQuoteAnalyzer;
		return Self;
	}

	public TextPropertyDescriptor Similarity(string? similarity)
	{
		SimilarityValue = similarity;
		return Self;
	}

	public TextPropertyDescriptor Store(bool? store = true)
	{
		StoreValue = store;
		return Self;
	}

	public TextPropertyDescriptor TermVector(Elastic.Clients.Elasticsearch.Serverless.Mapping.TermVectorOption? termVector)
	{
		TermVectorValue = termVector;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(AnalyzerValue))
		{
			writer.WritePropertyName("analyzer");
			writer.WriteStringValue(AnalyzerValue);
		}

		if (BoostValue.HasValue)
		{
			writer.WritePropertyName("boost");
			writer.WriteNumberValue(BoostValue.Value);
		}

		if (CopyToValue is not null)
		{
			writer.WritePropertyName("copy_to");
			JsonSerializer.Serialize(writer, CopyToValue, options);
		}

		if (DynamicValue is not null)
		{
			writer.WritePropertyName("dynamic");
			JsonSerializer.Serialize(writer, DynamicValue, options);
		}

		if (EagerGlobalOrdinalsValue.HasValue)
		{
			writer.WritePropertyName("eager_global_ordinals");
			writer.WriteBooleanValue(EagerGlobalOrdinalsValue.Value);
		}

		if (FielddataValue.HasValue)
		{
			writer.WritePropertyName("fielddata");
			writer.WriteBooleanValue(FielddataValue.Value);
		}

		if (FielddataFrequencyFilterDescriptor is not null)
		{
			writer.WritePropertyName("fielddata_frequency_filter");
			JsonSerializer.Serialize(writer, FielddataFrequencyFilterDescriptor, options);
		}
		else if (FielddataFrequencyFilterDescriptorAction is not null)
		{
			writer.WritePropertyName("fielddata_frequency_filter");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor(FielddataFrequencyFilterDescriptorAction), options);
		}
		else if (FielddataFrequencyFilterValue is not null)
		{
			writer.WritePropertyName("fielddata_frequency_filter");
			JsonSerializer.Serialize(writer, FielddataFrequencyFilterValue, options);
		}

		if (FieldsValue is not null)
		{
			writer.WritePropertyName("fields");
			JsonSerializer.Serialize(writer, FieldsValue, options);
		}

		if (IgnoreAboveValue.HasValue)
		{
			writer.WritePropertyName("ignore_above");
			writer.WriteNumberValue(IgnoreAboveValue.Value);
		}

		if (IndexValue.HasValue)
		{
			writer.WritePropertyName("index");
			writer.WriteBooleanValue(IndexValue.Value);
		}

		if (IndexOptionsValue is not null)
		{
			writer.WritePropertyName("index_options");
			JsonSerializer.Serialize(writer, IndexOptionsValue, options);
		}

		if (IndexPhrasesValue.HasValue)
		{
			writer.WritePropertyName("index_phrases");
			writer.WriteBooleanValue(IndexPhrasesValue.Value);
		}

		if (IndexPrefixesDescriptor is not null)
		{
			writer.WritePropertyName("index_prefixes");
			JsonSerializer.Serialize(writer, IndexPrefixesDescriptor, options);
		}
		else if (IndexPrefixesDescriptorAction is not null)
		{
			writer.WritePropertyName("index_prefixes");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor(IndexPrefixesDescriptorAction), options);
		}
		else if (IndexPrefixesValue is not null)
		{
			writer.WritePropertyName("index_prefixes");
			JsonSerializer.Serialize(writer, IndexPrefixesValue, options);
		}

		if (MetaValue is not null)
		{
			writer.WritePropertyName("meta");
			JsonSerializer.Serialize(writer, MetaValue, options);
		}

		if (NormsValue.HasValue)
		{
			writer.WritePropertyName("norms");
			writer.WriteBooleanValue(NormsValue.Value);
		}

		if (PositionIncrementGapValue.HasValue)
		{
			writer.WritePropertyName("position_increment_gap");
			writer.WriteNumberValue(PositionIncrementGapValue.Value);
		}

		if (PropertiesValue is not null)
		{
			writer.WritePropertyName("properties");
			JsonSerializer.Serialize(writer, PropertiesValue, options);
		}

		if (!string.IsNullOrEmpty(SearchAnalyzerValue))
		{
			writer.WritePropertyName("search_analyzer");
			writer.WriteStringValue(SearchAnalyzerValue);
		}

		if (!string.IsNullOrEmpty(SearchQuoteAnalyzerValue))
		{
			writer.WritePropertyName("search_quote_analyzer");
			writer.WriteStringValue(SearchQuoteAnalyzerValue);
		}

		if (!string.IsNullOrEmpty(SimilarityValue))
		{
			writer.WritePropertyName("similarity");
			writer.WriteStringValue(SimilarityValue);
		}

		if (StoreValue.HasValue)
		{
			writer.WritePropertyName("store");
			writer.WriteBooleanValue(StoreValue.Value);
		}

		if (TermVectorValue is not null)
		{
			writer.WritePropertyName("term_vector");
			JsonSerializer.Serialize(writer, TermVectorValue, options);
		}

		writer.WritePropertyName("type");
		writer.WriteStringValue("text");
		writer.WriteEndObject();
	}

	private Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter? BuildFielddataFrequencyFilter()
	{
		if (FielddataFrequencyFilterValue is not null)
		{
			return FielddataFrequencyFilterValue;
		}

		if ((object)FielddataFrequencyFilterDescriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter?> buildable)
		{
			return buildable.Build();
		}

		if (FielddataFrequencyFilterDescriptorAction is not null)
		{
			var descriptor = new Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilterDescriptor(FielddataFrequencyFilterDescriptorAction);
			if ((object)descriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.IndexManagement.FielddataFrequencyFilter?> buildableFromAction)
			{
				return buildableFromAction.Build();
			}
		}

		return null;
	}

	private Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes? BuildIndexPrefixes()
	{
		if (IndexPrefixesValue is not null)
		{
			return IndexPrefixesValue;
		}

		if ((object)IndexPrefixesDescriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes?> buildable)
		{
			return buildable.Build();
		}

		if (IndexPrefixesDescriptorAction is not null)
		{
			var descriptor = new Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixesDescriptor(IndexPrefixesDescriptorAction);
			if ((object)descriptor is IBuildableDescriptor<Elastic.Clients.Elasticsearch.Serverless.Mapping.TextIndexPrefixes?> buildableFromAction)
			{
				return buildableFromAction.Build();
			}
		}

		return null;
	}

	TextProperty IBuildableDescriptor<TextProperty>.Build() => new()
	{
		Analyzer = AnalyzerValue,
		Boost = BoostValue,
		CopyTo = CopyToValue,
		Dynamic = DynamicValue,
		EagerGlobalOrdinals = EagerGlobalOrdinalsValue,
		Fielddata = FielddataValue,
		FielddataFrequencyFilter = BuildFielddataFrequencyFilter(),
		Fields = FieldsValue,
		IgnoreAbove = IgnoreAboveValue,
		Index = IndexValue,
		IndexOptions = IndexOptionsValue,
		IndexPhrases = IndexPhrasesValue,
		IndexPrefixes = BuildIndexPrefixes(),
		Meta = MetaValue,
		Norms = NormsValue,
		PositionIncrementGap = PositionIncrementGapValue,
		Properties = PropertiesValue,
		SearchAnalyzer = SearchAnalyzerValue,
		SearchQuoteAnalyzer = SearchQuoteAnalyzerValue,
		Similarity = SimilarityValue,
		Store = StoreValue,
		TermVector = TermVectorValue
	};
}